package com.fbms.module.auth.controller;

import com.fbms.common.result.Res;
import com.fbms.common.result.ResBuilder;
import com.fbms.module.auth.Bean.LoginFormDTO;
import com.fbms.module.auth.Bean.LoginUserDTO;
import com.fbms.module.auth.service.ISysLoginService;
import com.fbms.module.auth.service.TokenService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类描述：Token
 *
 * @ClassName TokenController
 * @Author HappyBoy
 * @Date 2023-03-20 15:45
 **/
@RestController
@RequiredArgsConstructor
public class TokenController {

    /**
     * 用户
     */
    private final ISysLoginService sysLoginService;

    /**
     * token服务
     */
    private final TokenService tokenService;


    /**
     * 登录接口
     * @param loginForm 登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    public Res<LoginUserDTO> login(@RequestBody LoginFormDTO loginForm){
        LoginUserDTO login = sysLoginService.login(loginForm.getName(), loginForm.getPassword());
        LoginUserDTO res = tokenService.createToken(login);
        return ResBuilder.of(res);
    }


//    @PostMapping("register")
//    public Res<String> register(@RequestBody ){
//
//    }


}
